home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / education / pe022.dms / pe022.adf / GRAVSIM / README < prev    next >
Text File  |  1991-07-12  |  6KB  |  182 lines

  1.  
  2.     THE GRAVITY SIMULATOR:         Page 1
  3.  
  4.  
  5.     
  6.     
  7.                   A  Gravity Simulator Animation Program
  8.     
  9.                                     by
  10.     
  11.                          Richard Frost. (C) 1988
  12.     
  13.     
  14.     
  15.       Compilation:
  16.     
  17.            My program compiles under  both  Aztec  3.6a  and 3.2a. The
  18.     program runs easily with  1/2  Meg  and  will load the sprite data
  19.     into chip ram and the rest of  the  program  into FAST RAM (If you
  20.     are lucky enough to have any!!!).
  21.     
  22.            This program is a real number cruncher and would BURN with 
  23.     one of those 68020 and 68881 TURBO BOARDS!!
  24.     
  25.     
  26.        Bugs:
  27.     
  28.            Not many, I am happy to say !.  But there is this weird bug
  29.     that occurs if  you are  in  the  RECORD  mode  and  you add a new
  30.     planet. Then, when you  try  to  play  the  animation  back... you
  31.     guessed it !, you get a visit from the friendly neighbourhood GURU
  32.     !
  33.  
  34.     
  35.     
  36.       Basic Program Description:
  37.     
  38.            My program can animate up to  6  planetary  masses  all  of
  39.     which exert  a  mutual  gravitational  force  on  each  other. The
  40.     planetary masses can be placed  and  removed  from anywhere on the
  41.     screen and their mass and  initial  velocity can all be determined
  42.     by the user. The program then steps the animation through time, at
  43.     each stage plotting the new  position  in  the trajectory for each
  44.     mass on the screen. The animation  in this mode is obviously going
  45.     to be slow as the computer is calculating  the paths in real time.
  46.     It is for this reason  that  I  have  used  a  large array storage
  47.     technique involving the  use  of  a  look-up  table  to record the
  48.     positions of the masses for  each  step  in time. A record mode is
  49.     offered which allows the user at any  time to record the animation
  50.     calculated in real time  and  then  play  it  back at a variety of
  51.     speeds, this mode is useful as  the  complex  interactions between
  52.     various masses can be more  easily  appreciated when the animation
  53.     is played back at full speed.
  54.     
  55.  
  56.  
  57.  
  58.  
  59.     THE GRAVITY SIMULATOR:         Page 2
  60.  
  61.  
  62.     
  63.       Theory behind the animation:
  64.     
  65.            To animate N bodies, each applying some gravitational force
  66.     on all the other bodies we must consider  1 mass at a time and for
  67.     that mass evaluate the total force  vector applied to the mass due
  68.     to the gravitational force of  attraction  from  all the remaining
  69.     masses. We then work out the the new acceleration of the mass from
  70.     Newton's First Law and hence  it's  new  velocity and position. In
  71.     real life however, it  things  are  not  as  simple as this. In my
  72.     model  animation  I  have  ignored  possible  quantum  gravitional
  73.     effects such as  the  curvature  of  space-time  and  non constant
  74.     acceleration. My model behaves quite  well under the assumption of
  75.     constant acceleration,  this  allows  me  to use the simple motion
  76.     equation: V2 = V1 + At, which  increases  speed of calculation, as
  77.     equations  involving  non  constant   acceleration  would  involve
  78.     possible  Differential  Equations  and  numerical  methods,  for 3
  79.     situations involving 3 or more  masses.  My assumption of constant
  80.     acceleration is not incorrect  as  long  as I choose steps in time
  81.     which are relatively small when  compared  to  the mutual force of
  82.     attraction between 2 given masses .
  83.     
  84.             Some problems do  arise  when  2  masses  get  very  close
  85.     together. In this situation the gravitational  force is very large
  86.     (inversely proportional to the square  of the separtation of the 2
  87.     masses) and consequently if I  keep  the same icrements in time as
  88.     when the masses are far apart,  for  the next frame the masses may
  89.     pass each other by  and  thus  have  the  same  velocity vector as
  90.     before the  encounter  took  place.  This  results  in both masses
  91.     heading off to  infinity  (leaving  the  screen  very quickly) and
  92.     ending the animation. I partially  solved this problem by refining
  93.     (reducing) my  time  increments  appropriately  (in  fact  I use a
  94.     linear reduction which depends on the separation of the 2 masses.)
  95.     this  is  seen  in   the   section   of   C-code  in  the  routine
  96.     GravityAttract which obtains the  new  X & Y velocities of a given
  97.     mass   M1 due to the force applied by mass M2 :
  98.     
  99.                   If (r < 2000 )
  100.                     {
  101.                       TimeStep = r * 0.04 + 1;
  102.                     }
  103.                   else
  104.                       TimeStep = 80.0;
  105.     
  106.     where 'r' is the separation of the 2 masses. The number '0.04' was
  107.     arrived at after af few  runs  of  the  program  and analysing how
  108.     close planets could get without unexpectantly  leaving the screen.
  109.     This code part worked quite well  and  reduced the number of times
  110.     planets would fling off  and  leave  the  screen when they got too
  111.     close. This   problem  is  always  there  and  is  inherent in its
  112.     algorithmic description, I know of  no other simple technique that
  113.     comlpletely solves this problem.
  114.     
  115.     
  116.       Extra Notes: 
  117.  
  118.  
  119.  
  120.  
  121.     THE GRAVITY SIMULATOR:         Page 3
  122.  
  123.  
  124.     
  125.          Because of my program's  generality  it is possible to set up
  126.     animations involving the  animation  of  say, comet paths around a
  127.     star or very massive object and the familiar wobble motion a start
  128.     exhibits when it has  planets  orbiting  it  (Astronomers look for
  129.     this motion of a star to determine whether it has planets orbiting
  130.     around it. Also, due to the  way  I  store  the position values of
  131.     masses  in the look-up  table,  masses  are  animated with various
  132.     speeds, this is due to the storing  of multiple copies of the same
  133.     position of a given mass in the  look-up  table.  I decided not to
  134.     store a position value and a count  as my table uses more then one
  135.     object thus you cannot  have  situations  where  large consecutive
  136.     portions of the array contain the same postion values.
  137.          
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.